<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
  <HEAD>
<!--

  %W% %E% %Z%
 
  Copyright (c) 2000-2002 Sun Microsystems, Inc.  All rights reserved.
  PROPRIETARY/CONFIDENTIAL
  Use is subject to license terms.

-->
    <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
    <TITLE>Performance Monitoring package</TITLE>
    <!-- Changed by: Gary Adams - SMI Software Development, 06-May-2002 -->
    <META NAME="GENERATOR" CONTENT="StarOffice/5.2 (Solaris Sparc)">
    <META NAME="AUTHOR" CONTENT="Kerry Finn">
    <META NAME="CREATED" CONTENT="20010211;22512640">
    <META NAME="CHANGEDBY" CONTENT=" ">
    <META NAME="CHANGED" CONTENT="20010718;13050000">
    <style>
      <!--
	   body, td, tr, table, p, h1, h2, h3, h4, li, ul, th, caption { font-family: sans-serif; }
	   .box { margin-right: 3%; margin-left: 3%; padding: 0.2em; border: solid thin; width: 100% }
	   pre { color: green; font-weight: bold; font-family: monospace }
	   .header { font-family: sans-serif; margin-right: 0 }
      -->
    </style>
  </HEAD>
  <BODY>
    <P>This class provides a standard method
      of reporting and analyzing performance monitoring information.
      It also provides a
      number of methods and measurements 
      to help diagnose and analyze potential performance bottlenecks.</P>
    <h2>
      Performance Monitoring Utility </h2>
    <h3>Programming
	  and User Guide</h3>
    <P>Add the
      appropriate &quot;perfmon&quot; import and calls to your
      application.</P> 
    
    <DIV  class="box"><CODE><PRE>    
/*
 * Copyright &copy; 2001, Sun Microsystems Inc.
 * NAME: fasterhttp.java
 * DESCRIPTION: example java program using the perfmon package.
 */

/* import the PerfMon package */
import com.sun.midp.perfmon.*;

/**
 * Performance monitoring class for faster http tuning.
 */    
public class fasterhttp extends MIDlet 
    implements CommandListener, Runnable {
    
    /** Define midlet command object. */
    Command bye_command = new Command(Exit, Command.EXIT, 2);
    
    /** Define the perfmon instance. */
    private PerfMon perfmon;
    
    /** Constructor for fasterhttp class. */
    public fasterhttp() {
	
	/* Create the perfmon instance. */
	perfmon = new PerfMon(&quot;Protocol(reallyHttpConnection)&quot;);
	
    } /* end constructor */
      
    /**
     * Run method for the runnable thread object. 
     */
    public void run() 
	
	/* Start the performance analysis. */
	long start = perfmon.start(&quot;run()&quot;);
    
        while ((ch = input.read()) != -1) {
	    if (ch &lt;= ' ') {
		ch = ' ';
	    }
	    
	    buffer.append((char ch);
			  }
	    
	    /* End the performance analysis. */
	    long end = perfmon.end();
	    
	    /* Report (stdout) performance analysis. */
	    perfmon.report(System.out);
	    
	} /* end run */
    
} /* end class */
	  </PRE> </CODE></DIV>
   <P>Use the
	    &quot;ENABLEPROFILING=true&quot; macro when building.</P>
    <DIV  class="box"> <CODE><PRE>
% gnumake -e ENABLEPROFILING=true</PRE></CODE></DIV>
    
    <P>Example Performance Monitor Report Output:</P> 
    <DIV class="box"> <CODE>
    <PRE>
      ========================================================================
      Performance Monitor Tracing Report
      Application Name: [Protocol(HttpConnection)
      Report Date: [Mon, 12 Feb 2001 18:30:28 GMT (06:30 pm)]
      ========================================================================

      ------------------------------------------------------------------------
      Performance Monitor - Snapshot Analysis - 

      TimeStamp: [Mon, 12 Feb 2001 18:30:28 GMT (06:30 pm)]
      Class Name: [Protocol(HttpConnection)]
      Method Name: [run()]
      Comments: [read() performance monitoring[ line number 329 ]]
      Elapsed Time : [344] (milli-seconds)
      Classname: [Protocol(HttpConnection)]
      Instruction Count: [566266]
      Thread Switch Count: [0]
      Dynamic Object Count: [268]
      Dynamic Alloc Count: [57972]
      Dynamic Dealloc Count: [0]
      Garbage Collect Count: [0]
      GC Deferrals: [0]
      Maximum GC Deferrals: [0]
      Garbage Collect Rescans:[0]
      -----------------------------------------------------------------------
      Execution completed successfully
      1099922 bytecodes executed
      77 thread switches
      236 classes in the system (including system classes)
      1481 dynamic objects allocated (187364 bytes)
      6 garbage collections (4324 bytes collected)
      
	Total heap size 500000 bytes (currently 304672 bytes free)
    </PRE></CODE> </DIV>

@since MIDP 1.0
  </BODY>
</HTML>
